import java.util.ArrayList;
import java.util.List;

public class Solution78 {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> ans=new ArrayList<>();
        List<Integer> temp=new ArrayList<>();
        dfs(0,nums,temp,ans);
        return ans;
    }

    private void dfs(int k, int[] nums, List<Integer> temp, List<List<Integer>> ans) {
        if (k==nums.length){
            ans.add(new ArrayList<>(temp));
            return;
        }
        dfs(k+1,nums,temp,ans);
        temp.add(nums[k]);
        dfs(k+1,nums,temp,ans);
        temp.remove(temp.size()-1);
    }

    public static void main(String[] args) {
        System.out.println(new Solution78().subsets(new int[]{1,2,3}));
    }
}
